package com.base.chat.ac;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.Spannable;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.base.chat.R;
import com.base.chat.adapter.Adapter_ChatMessage;
import com.base.chat.bean.ChatMessage;
import com.base.chat.im.JWebSocketClient;
import com.base.chat.im.JWebSocketClientService;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;


@Route(path = "/chat/chat_window2")
public class ChatActivity2 extends FragmentActivity{
    private JWebSocketClient client;
    private JWebSocketClientService.JWebSocketClientBinder binder;
    private JWebSocketClientService jWebSClientService;
    private List<ChatMessage> chatMessageList = new ArrayList<>();//消息列表
    private Adapter_ChatMessage adapter_chatMessage;
    RecyclerView rcvContent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chat2);
        rcvContent = (RecyclerView) findViewById(R.id.rcv_content);
        rcvContent.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
//        initKeyBoard();
//        initRecycleView();
//        initEmoticonsView();
//
//        initAppFuncView();

    }
    private void initRecycleView() {
        rcvContent = (RecyclerView) findViewById(R.id.rcv_content);
        rcvContent.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

//        rcvContent.setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View view, MotionEvent motionEvent) {
//                if (null != cbEmoticonsKeyBoard) {
//                    cbEmoticonsKeyBoard.reset();
//                }
//                return false;
//            }
//        });
    }
//    CBEmoticonsKeyBoard cbEmoticonsKeyBoard;
//    private void initKeyBoard() {
//        cbEmoticonsKeyBoard = (CBEmoticonsKeyBoard) findViewById(R.id.ekb_emoticons_keyboard);
//
//        cbEmoticonsKeyBoard.addOnFuncKeyBoardListener(new FuncLayout.OnFuncKeyBoardListener() {
//            @Override
//            public void onFuncPop(int height) {
//                Toast.makeText(ChatActivity2.this, "xxxx", Toast.LENGTH_SHORT).show();
//            }
//
//            @Override
//            public void onFuncClose() {
//                Toast.makeText(ChatActivity2.this, "xxxx", Toast.LENGTH_SHORT).show();
//            }
//
//        });
//
//        cbEmoticonsKeyBoard.getBtnSend().setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                cbEmoticonsKeyBoard.getEtChat().setText("");
//            }
//        });
//    }

//    private void initEmoticonsView() {
//        CBEmoticonsView cbEmoticonsView = new CBEmoticonsView(this);
//        cbEmoticonsView.init(getSupportFragmentManager());
//        cbEmoticonsKeyBoard.setEmoticonFuncView(cbEmoticonsView);
//
//        cbEmoticonsView.addEmoticonsWithName(new String[]{"default", "ali1", "ali2", "ali3", "sibi", "jinguanzhang"});
////
//        cbEmoticonsView.setOnEmoticonClickListener(new CBEmoticonsView.OnEmoticonClickListener() {
//            @Override
//            public void onEmoticonClick(EmoticonsBean emoticon, boolean isDel) {
//                if (isDel) {
//                    Log.i("onEmoticonClick", "delete");
//                    cbEmoticonsKeyBoard.delClick();
//                } else {
//                    if ("default".equals(emoticon.getParentTag())) {
//                        String content = emoticon.getName();
//                        if (TextUtils.isEmpty(content)) {
//                            return;
//                        }
//                        int index = cbEmoticonsKeyBoard.getEtChat().getSelectionStart();
//                        Editable editable = cbEmoticonsKeyBoard.getEtChat().getText();
//                        editable.insert(index, content);
//                    } else {
//                        String text = "bigEmoticon : " + " - [" + emoticon.getName() + "] - " + emoticon.getParentId() + " - " + emoticon.getId() + "." + emoticon.getIconType();
//                        Toast.makeText(ChatActivity2.this, text, Toast.LENGTH_SHORT).show();
//                        Log.i("onEmoticonClick", text);
//                    }
//
//                }
//            }
//        });
//    }
//
//    private void initAppFuncView() {
//        CBAppFuncView cbAppFuncView = new CBAppFuncView(this);
//        cbEmoticonsKeyBoard.setAppFuncView(cbAppFuncView);
//        List<AppFuncBean> appFuncBeanList = new ArrayList<>();
//        appFuncBeanList.add(new AppFuncBean(R.mipmap.ic_yongyingdengji, "图片"));
//        appFuncBeanList.add(new AppFuncBean(R.mipmap.ic_yongyingdengji, "兼职"));
//        appFuncBeanList.add(new AppFuncBean(R.mipmap.ic_yongyingdengji, "快捷回复"));
//        appFuncBeanList.add(new AppFuncBean(R.mipmap.ic_yongyingdengji, "定位"));
//        appFuncBeanList.add(new AppFuncBean(R.mipmap.ic_yongyingdengji, "图片"));
//        appFuncBeanList.add(new AppFuncBean(R.mipmap.ic_yongyingdengji, "兼职"));
//        appFuncBeanList.add(new AppFuncBean(R.mipmap.ic_yongyingdengji, "快捷回复"));
//        appFuncBeanList.add(new AppFuncBean(R.mipmap.ic_yongyingdengji, "定位"));
//        cbAppFuncView.setAppFuncBeanList(appFuncBeanList);
//        cbAppFuncView.setOnAppFuncClickListener(new CBAppFuncView.OnAppFuncClickListener() {
//            @Override
//            public void onAppFunClick(AppFuncBean emoticon) {
//                String text = emoticon.getTitle();
//                Toast.makeText(ChatActivity2.this, text, Toast.LENGTH_SHORT).show();
//                Log.i("onAppFunClick", text);
//            }
//        });
//    }


}
